{extend name='base' /}
{block name='content'}
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
         <a href="">后台管理</a>
        <a href="">管理员管理</a>
        <a>
          <cite>管理员列表</cite></a>
      </span>
  <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
  <div class="layui-row">
    <form class="layui-form layui-col-md12 x-so">

      <input type="text" name="username"  placeholder="请输入登录名" class="layui-input" value="{$username=isset($_GET['username'])?$_GET['username']:'';}">
      <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
    </form>
  </div>
  <xblock>
    <button class="layui-btn" onclick="x_admin_show('添加用户','{:url('role/adminadd')}')"><i class="layui-icon"></i>添加</button>

  </xblock>
  <table class="layui-table">
    <thead>
    <tr>

      <th>ID</th>
      <th>登录名</th>
      <th>角色</th>
      <th>加入时间</th>
      <th>状态</th>
      <th>操作</th>
    </thead>
    <tbody>
    {volist name='adminData' id='vo'}
    <tr>

      <td>{$vo.admin_id}</td>
      <td>{$vo.username}</td>
      <td>{$vo.role_name}</td>
      <td>{$vo.create_time}</td>
      <td class="td-status">
        {if $vo.status==1}
        <span class="layui-btn layui-btn-normal layui-btn-xs">已启用</span>
      {else /}
        <span class="layui-btn layui-btn-danger layui-btn-xs">已禁用</span>
        {/if}
      </td>
      <td class="td-manage">
        <div class="layui-btn-group">
          <a onclick="member_stop(this,{$vo.admin_id})" href="javascript:;"
             class="layui-btn layui-btn-warm layui-btn-xs" stu="{$vo.status}">停用</a>
          <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="member_del(this,{$vo.admin_id})"
             href="javascript:;">删除</a>
          <a class="layui-btn layui-btn-info layui-btn-xs" onclick="x_admin_show('编辑','{:url('role/adminedit','id='.$vo['admin_id'])}');"
             href="javascript:;">编辑</a>
        </div>
      </td>
    </tr>
    {/volist}
    </tbody>
  </table>
  <div class="page">
    <div>
     {$adminData->render()}
    </div>
  </div>

</div>
<script>


    /*用户-停用*/
    function member_stop(obj, id) {
        var sta = $(obj).attr('stu');
        if (sta==1){
            var str ='确认要停用吗？'
        } else{
            var str ='确认要启用吗？'
        }
        layer.confirm(str, function (index) {
            $.ajax({
                url:"{:url('role/upadminsta')}",
                type:'post',
                dataType:'json',
                data:{id:id,sta:sta},
                success:function (res) {
                    if (res.code) {
                        if (sta==1) {

                            //发异步把用户状态进行更改
                            $(obj).attr('stu', '0')
                            $(obj).html('启用')
                            $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-danger').html('已禁用');
                            layer.msg(res.message, {icon: 6, time: 1000});

                        } else {
                            $(obj).attr('stu', '1')
                            $(obj).html('停用')
                            $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-danger').html('已启用');
                            layer.msg(res.message, {icon: 6, time: 1000});
                        }

                    } else {
                        layer.msg(res.message, {icon: 2, time: 1000})
                    }
                },
                error:function () {
                    layer.msg('出错了，请稍后再试！！', {icon: 5, time: 1000})
                }
            })


        });
    }

    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            // //发异步删除数据
            $.ajax({
                url: "{:url('role/admindel')}",
                data: {id: id},
                type: 'post',
                dataType: 'json',
                success: function (res) {
                    if (res.code) {
                        $(obj).parents("tr").remove();
                        layer.msg(res.message, {icon: 6, time: 1000});
                    } else {
                        layer.msg(res.message, {icon: 2, time: 1000})
                    }
                },
                error: function () {
                    layer.msg('出错了，请稍后再试！！', {icon: 5, time: 1000})
                }
            })

        });
    }



</script>

</body>
{/block}